//
//  TripsQueueCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-28.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TripsQueueCell.h"

@implementation TripsQueueCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.imageview = [[UIImageView alloc] init];
        self.imageView.contentMode = UIViewContentModeScaleAspectFill;
        self.imageview.layer.cornerRadius = 5;
        // 裁剪图片超出边框部分
        self.imageview.clipsToBounds = YES;
        [self.contentView addSubview:self.imageview];
        [_imageview release];
        
        self.nameLabel = [[UILabel alloc] init];
        [self.imageview addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.dayLabel = [[UILabel alloc] init];
        [self.imageview addSubview:self.dayLabel];
        [_dayLabel release];
        self.dayImage = [[UIImageView alloc] init];
        [self.dayLabel addSubview:self.dayImage];
        [_dayImage release];
        
        self.placeLabel = [[UILabel alloc] init];
        [self.imageview addSubview:self.placeLabel];
        [_placeLabel release];
        
        // 左下角头像文字
        self.photoLabel = [[UILabel alloc] init];
        [self.imageview addSubview:self.photoLabel];
        [_photoLabel release];
        
        self.photoImage = [[UIImageView alloc] init];
        [self.imageview addSubview:self.photoImage];
        [_photoImage release];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.contentView.frame.size.width;
    CGFloat heigth = self.contentView.frame.size.height;
    
    self.imageview.frame = CGRectMake(10, 5, width - 20, heigth - 10);
    NSURL *url = [NSURL URLWithString:self.tripsQueue.cover_image_w640];
    [self.imageview setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    self.nameLabel.frame = CGRectMake(10, 10, width - 30, 20);
    self.nameLabel.textColor = [UIColor whiteColor];
//    self.nameLabel.text = self.tripsQueue.name;
    self.nameLabel.shadowColor = [UIColor blackColor];
    self.nameLabel.shadowOffset = CGSizeMake(1, 1);
    self.nameLabel.numberOfLines = 0;
    [self.nameLabel sizeToFit];
    
    self.dayImage.frame = CGRectMake(0, 0, 3, 20);
//    self.dayImage.image = [UIImage imageNamed:@"ticket_@2x.png"];
    
    self.dayLabel.frame = CGRectMake(10, self.nameLabel.frame.size.height + 10, width - 30, 10);
//    self.dayLabel.text = [NSString stringWithFormat:@"  %@天 %@次浏览", self.tripsQueue.day_count, self.tripsQueue.recommendations];
    self.dayLabel.shadowColor = [UIColor blackColor];
    self.dayLabel.shadowOffset = CGSizeMake(1, 1);
    self.dayLabel.textColor = [UIColor whiteColor];
    self.dayLabel.font = [UIFont systemFontOfSize:10];
    
    self.placeLabel.frame = CGRectMake(10, self.nameLabel.frame.size.height + 20, width - 30, 10);
//    self.placeLabel.text = [NSString stringWithFormat:@"  %@", self.tripsQueue.popular_place_str];
    self.placeLabel.shadowColor = [UIColor blackColor];
    self.placeLabel.shadowOffset = CGSizeMake(1, 1);
    self.placeLabel.textColor = [UIColor whiteColor];
    self.placeLabel.font = [UIFont systemFontOfSize:10];
    
    self.photoLabel.frame = CGRectMake(50, self.imageview.frame.size.height - 50, self.imageview.frame.size.width - 20, 40);
    self.photoLabel.textColor = [UIColor whiteColor];
    self.photoLabel.font = [UIFont systemFontOfSize:12];
    
    self.photoImage.frame = CGRectMake(10, self.imageview.frame.size.height - 45, 30, 35);
    self.photoImage.layer.cornerRadius = 15;
    self.photoImage.clipsToBounds = YES;
    
}
-(void)setTripsQueue:(TripsQueue *)tripsQueue
{
    if (_tripsQueue != tripsQueue) {
        [_tripsQueue release];
        _tripsQueue = [tripsQueue retain];
    }
    self.nameLabel.text = self.tripsQueue.name;
    self.dayImage.image = [UIImage imageNamed:@"ticket_@2x.png"];
    self.dayLabel.text = [NSString stringWithFormat:@"  %@天 %@次浏览", self.tripsQueue.day_count, self.tripsQueue.recommendations];
    self.placeLabel.text = [NSString stringWithFormat:@"  %@", self.tripsQueue.popular_place_str];
    self.photoLabel.text = [NSString stringWithFormat:@" by %@", [self.tripsQueue.user objectForKey:@"name"]];
    NSURL *url = [NSURL URLWithString:[self.tripsQueue.user objectForKey:@"avatar_m"]];
    [self.photoImage setImageWithURL:url];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
